package org.cpoy.ei.session;

import org.cpoy.eims.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("studentCerficateHome")
public class StudentCerficateHome extends EntityHome<StudentCerficate> {

	@In(create = true)
	StudentHome studentHome;
	@In(create = true)
	CertificateHome certificateHome;

	public void setStudentCerficateId(Integer id) {
		setId(id);
	}

	public Integer getStudentCerficateId() {
		return (Integer) getId();
	}

	@Override
	protected StudentCerficate createInstance() {
		StudentCerficate studentCerficate = new StudentCerficate();
		return studentCerficate;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Student student = studentHome.getDefinedInstance();
		if (student != null) {
			getInstance().setStudent(student);
		}
		Certificate certificate = certificateHome.getDefinedInstance();
		if (certificate != null) {
			getInstance().setCertificate(certificate);
		}
	}

	public boolean isWired() {
		if (getInstance().getStudent() == null)
			return false;
		if (getInstance().getCertificate() == null)
			return false;
		return true;
	}

	public StudentCerficate getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<StudentCertificateLocation> getStudentCertificateLocations() {
		return getInstance() == null ? null
				: new ArrayList<StudentCertificateLocation>(getInstance()
						.getStudentCertificateLocations());
	}

}
